(function (exports) {
	exports.fillArray = fillArray;
	exports.randomUpTo = randomUpTo;
	exports.createMineFieldDesigner = createMineFieldDesigner;
	
	function fillArray(howMany, item) {	
		var array = [];
		for (var i=0; i<howMany; i++){
			if (typeof item == 'function'){
				array.push(item());
			} else {
				array.push(item);
			}
		}
		return array;
	}
	
	function randomUpTo(n) {
		return Math.floor(Math.random() * n);
	}

	function createMineFieldDesigner(){
                return {
                        create : function createTheGrid(width, height, clickedCoord) {
                                function notTheClickedTile(x,y) {
                                        return (x !== clickedCoord.x) && (y !== clickedCoord.y);
                                }

                                var grid = fillArray(height, function() { return fillArray(width, false)} );
                                var mines = 10;
                                while (mines > 0) {
                                        var x = randomUpTo(height);
                                        var y = randomUpTo(width);

                                        if (notTheClickedTile(x,y) && !grid[y][x]) {
                                                grid[y][x] = true;
                                                mines = mines - 1;
                                        }
                                }
                                return grid;
                        }
                }
        }
})(typeof exports === 'undefined' ? this['utils']={} : exports);
